package com.scpii.api.domain.ec;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.map.annotate.JsonSerialize;

import com.scpii.api.common.Constants;
import com.scpii.api.common.base.FilterEntity;
import com.scpii.api.common.json.serializer.ResourceUrlSerializer;
import com.scpii.api.domain.content.Body;

public class Product extends FilterEntity {
	private static final long serialVersionUID = 1L;

	private Long productId;

	@JsonIgnore
	private Long appId;

	private Long catId;

	private String title;

	private String summary;

	private List<Body> body;

	private String listPrice;

	private Float price;
	
	private Integer paymentType;
	
	private Integer storeQuantity;
	
	private Integer sortOrders;

	@JsonSerialize(using = ResourceUrlSerializer.class, include = JsonSerialize.Inclusion.NON_NULL)
	private String thumbImage;

	private Integer isReal;

	private Integer giveUserPoints;

	private Float ratingAvg;

	@JsonIgnore
	private Integer publish;

	private Integer reviewsCount;

	private Integer orderCount;

	private Integer favCount;

	private Integer commentCount;

	private List<String> images;

	@JsonIgnore
	private Date createDt;
	@JsonIgnore
	private String createBy;
	@JsonIgnore
	private Date updateDt;
	@JsonIgnore
	private String updateBy;
	
	private String columnAlias;

	public Long getProductId() {
		return productId;
	}

	public void setProductId(Long productId) {
		this.productId = productId;
	}


	public Long getAppId() {
		return appId;
	}

	public void setAppId(Long appId) {
		this.appId = appId;
	}

	public Long getCatId() {
		return catId;
	}

	public void setCatId(Long catId) {
		this.catId = catId;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getSummary() {
		return summary;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}

	public List<Body> getBody() {
		return body;
	}

	public void setBody(List<Body> body) {
		this.body = body;
	}

	public String getListPrice() {
		return listPrice;
	}

	public void setListPrice(String listPrice) {
		this.listPrice = listPrice;
	}

	public Float getPrice() {
		return price;
	}

	public void setPrice(Float price) {
		// 精确到小数点后两位
		DecimalFormat df = new DecimalFormat("##0.00");
		String p = df.format(price);
		this.price = Float.parseFloat(p);
	}

	public Integer getStoreQuantity() {
		return storeQuantity;
	}

	public void setStoreQuantity(Integer storeQuantity) {
		this.storeQuantity = storeQuantity;
	}

	public String getThumbImage() {
		return thumbImage;
	}

	public void setThumbImage(String thumbImage) {
		this.thumbImage = thumbImage;
	}

	public Integer getIsReal() {
		return isReal;
	}

	public void setIsReal(Integer isReal) {
		this.isReal = isReal;
	}

	public Integer getPaymentType() {
		return paymentType;
	}

	public void setPaymentType(Integer paymentType) {
		this.paymentType = paymentType;
	}

	public Integer getGiveUserPoints() {
		return giveUserPoints;
	}

	public void setGiveUserPoints(Integer giveUserPoints) {
		this.giveUserPoints = giveUserPoints;
	}

	public Float getRatingAvg() {
		return ratingAvg;
	}

	public void setRatingAvg(Float ratingAvg) {
		this.ratingAvg = ratingAvg;
	}


	public Integer getPublish() {
		return publish;
	}

	public void setPublish(Integer publish) {
		this.publish = publish;
	}

	public Integer getReviewsCount() {
		return reviewsCount;
	}

	public void setReviewsCount(Integer reviewsCount) {
		this.reviewsCount = reviewsCount;
	}

	public Integer getOrderCount() {
		return orderCount;
	}

	public void setOrderCount(Integer orderCount) {
		this.orderCount = orderCount;
	}

	public Integer getFavCount() {
		return favCount;
	}

	public void setFavCount(Integer favCount) {
		this.favCount = favCount;
	}

	public Integer getCommentCount() {
		return commentCount;
	}

	public void setCommentCount(Integer commentCount) {
		this.commentCount = commentCount;
	}

	public Date getCreateDt() {
		return createDt;
	}

	public void setCreateDt(Date createDt) {
		this.createDt = createDt;
	}

	public String getCreateBy() {
		return createBy;
	}

	public void setCreateBy(String createBy) {
		this.createBy = createBy;
	}

	public Date getUpdateDt() {
		return updateDt;
	}

	public void setUpdateDt(Date updateDt) {
		this.updateDt = updateDt;
	}

	public String getUpdateBy() {
		return updateBy;
	}

	public void setUpdateBy(String updateBy) {
		this.updateBy = updateBy;
	}

	public List<String> getImages() {
		return images;
	}


	public void setImages(List<String> images) {
		List<String> list = new ArrayList<String>();
		// 设置每个image为绝对路径
		for (String image : images) {
			if (!image.startsWith("http")) {
				image = StringUtils.startsWith(image, "/") ? image : "/" + image;
				image = Constants.RESOURCE_ROOT_URL + image;
			}
			list.add(image);
		}
		this.images = list;
	}

	public String getColumnAlias() {
		return columnAlias;
	}

	public void setColumnAlias(String columnAlias) {
		this.columnAlias = columnAlias;
	}

	public Integer getSortOrders() {
		return sortOrders;
	}

	public void setSortOrders(Integer sortOrders) {
		this.sortOrders = sortOrders;
	}
	
}